package com.example.dream.learnandroid;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

public class CheckBoxActivity extends AppCompatActivity {

    private CheckBox mCheckBoxProgram;
    private CheckBox mCheckBoxCooking;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_box);

        mCheckBoxProgram = findViewById(R.id.cb_program);
        mCheckBoxCooking = findViewById(R.id.cb_cook);

        mCheckBoxProgram.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                Toast.makeText(CheckBoxActivity.this, b ? "编程选中" : "编程未选中", Toast.LENGTH_SHORT).show();
            }
        });

        mCheckBoxCooking.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                Toast.makeText(CheckBoxActivity.this, b ? "做饭选中" : "做饭未选中", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
